package cn.kbyue.batchdemo.step;

import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.NonTransientResourceException;
import org.springframework.batch.item.ParseException;
import org.springframework.batch.item.UnexpectedInputException;

/**
 * @author XL
 * @version 0.1
 * @date 2022/1/13 17:44
 */
public class Reader implements ItemReader<String> {

    private String[] message = {"ganyu", "keqing", "kelee"};

    private int count = 0;

    /**
     * 注意(默认): String 类型返回 null 就结束了
     */
    @Override
    public String read() throws Exception, UnexpectedInputException, ParseException, NonTransientResourceException {
        if (count < message.length) {
            return message[count++];
        } else {
            count = 0;
        }
        return null;
    }
}
